package com.dxy.data.webcloud.up2u.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @CLassName: ApplicationContextRegister
 * @Author: weixin
 * @Description: TODO
 * @DATE: 2018/10/9 下午3:48
 * @Version: 1.0
 */
@Component
public class ApplicationContextRegister implements ApplicationContextAware {

    private final static Logger logger = LoggerFactory.getLogger(ApplicationContextRegister.class);

    private static ApplicationContext APPLICATION_CONTEXT;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        APPLICATION_CONTEXT = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return APPLICATION_CONTEXT;
    }

    public static <T> T getBean(Class<T> tClass) {
        return APPLICATION_CONTEXT.getBean(tClass);
    }
}
